var genderResult;
var salaryResult;
var educationResult;
$.ajax({
    type: "get",
    url: "/employerManager/getGenderCount",
    async: false,
    // 同步
    success: function (result) {
        genderResult=result
    }
});
$.ajax({
    type: "get",
    url: "/employerManager/getSalaryCount",
    async: false,
    // 同步x
    success: function (result) {
        salaryResult=result

    }
});
$.ajax({
    type: "get",
    url: "/employerManager/getEducationCount",
    async: false,
    // 同步
    success: function (result) {
        educationResult=result
    }
});
console.log(educationResult)
// 基于准备好的dom，初始化echarts实例
var a=educationResult.countEducation
var myChart = echarts.init(document.getElementById('gender'));
var salaryChart = echarts.init(document.getElementById('salary'));
var educationChart = echarts.init(document.getElementById('education'));



var option = {
    title:{
    text:'性别统计',
    padding:3,
        left:'left'
    },
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        x: 'center',
        data:['男','女'],
        type:'scroll'
    },
    series: [
        {
            name:'员工性别比率',
            type:'pie',
            radius: ['30%', '50%'],
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data:[
                {value:genderResult.countGender.male, name:'男'},
                {value:genderResult.countGender.female, name:'女'},
                // {value:234, name:'联盟广告'},
                // {value:135, name:'视频广告'},
                // {value:1548, name:'搜索引擎'}
            ]
        }
    ]
};
var optionSalary = {
    title:{
        text:'工资统计',
        left:'left'
    },
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        x: 'center',
        data:['>10k','<10k'],
        type:'scroll'
    },
    series: [
        {
            name:'员工工资比率',
            type:'pie',
            radius: ['30%', '50%'],
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data:[
                {value:salaryResult.countSalary.salaryCount, name:'>10k'},
                {value:salaryResult.countSalary.allUser-salaryResult.countSalary.salaryCount, name:'<10k'},
                // {value:234, name:'联盟广告'},
                // {value:135, name:'视频广告'},
                // {value:1548, name:'搜索引擎'}
            ]
        }
    ]
};
var optionEducation = {
    title: {
        text: '人力资源公司学历组成（单位:人）',
        // subtext: 'From ExcelHome',
        // sublink: 'http://e.weibo.com/1341556070/AjQH99che'
    },
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        },
        formatter: function (params) {
            var tar = params[1];
            return tar.name + '<br/>' + tar.seriesName + ' : ' + tar.value;
        }
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type : 'category',
        splitLine: {show:false},
        data : ['总人数','研究生以上','研究生','本科','大专','大专以下']
    },
    yAxis: {
        type : 'value'
    },
    series: [
        {
            name: '辅助',
            type: 'bar',
            stack:  '总量',
            itemStyle: {
                normal: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                },
                emphasis: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                }
            },
            data: [0,salaryResult.countSalary.allUser- a.研究生以上, salaryResult.countSalary.allUser- a.研究生-a.研究生以上, salaryResult.countSalary.allUser- a.本科- a.研究生-a.研究生以上, salaryResult.countSalary.allUser- a.带专- a.本科- a.研究生-a.研究生以上, 0]
        },
        {
            name: '学历',
            type: 'bar',
            stack: '总量',
            label: {
                normal: {
                    show: true,
                    position: 'inside'
                }
            },
            data:[salaryResult.countSalary.allUser, a.研究生以上, educationResult.countEducation.研究生, educationResult.countEducation.本科, educationResult.countEducation.带专,educationResult.countEducation.带专以下]
        }
    ]
};

// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
salaryChart.setOption(optionSalary);
educationChart.setOption(optionEducation);